package me.zhengjie.modules.website.service.impl;

import me.zhengjie.modules.website.domain.UserColumn;
import me.zhengjie.modules.website.repository.UserColumnRepository;
import me.zhengjie.modules.website.repository.UserColumnSpecifications;
import me.zhengjie.modules.website.service.UserColumnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import me.zhengjie.modules.website.domain.PageResult;

import java.util.List;

/**
 * @author system
 * @since 2024-12-10 22:32:50
 */
@Service
public class UserColumnServiceImpl implements UserColumnService {

    @Autowired
    private UserColumnRepository userColumnRepository;

    @Override
    public PageResult<UserColumn> findPage(UserColumn userColumn, Pageable pageable) {
        Page<UserColumn> page = userColumnRepository.findAll(UserColumnSpecifications.queryList(userColumn), pageable);
        PageResult<UserColumn> result = new PageResult();
        result.setContent(page.getContent());
        result.setTotalElements(page.getTotalElements());
        return result;
    }

    @Override
    public List<UserColumn> findList(UserColumn userColumn) {
        return userColumnRepository.findAll(UserColumnSpecifications.queryList(userColumn));
    }

    @Override
    public UserColumn findById(Long id) {
        return userColumnRepository.findById(id).orElse(null);
    }

    @Override
    public UserColumn insert(UserColumn userColumn) {
        return userColumnRepository.save(userColumn);
    }

    @Override
    public UserColumn update(UserColumn userColumn) {
        return userColumnRepository.saveAndFlush(userColumn);
    }

    @Override
    public void delete(Long id) {
        userColumnRepository.deleteById(id);
    }

}